package stdHttp

import (
	"fmt"
	"net/http"
	"os"
)

func sayHello(w http.ResponseWriter, r *http.Request) {
	data, errReadFile := os.ReadFile("stdHttp/hello.html")
	if errReadFile != nil {
		fmt.Fprintf(w, fmt.Sprintf("open html file fail, %v", errReadFile))
		return
	}
	_, _ = fmt.Fprintf(w, string(data))
}

func sayHello1(w http.ResponseWriter, r *http.Request) {
	_, _ = fmt.Fprintf(w, "<h1>hello</h1>")
}

func Start() {
	http.HandleFunc("/", sayHello)

	errListen := http.ListenAndServe(":8080", nil)
	if errListen != nil {
		fmt.Printf("http start failed, err:%+v\n", errListen)
	}
}
